cmake_minimum_required(VERSION 3.1.3)  # 设置cmake版本 --VERSION 3.1.3
project(speech_test)  # 设置项目名称

set(speech_path ${CMAKE_CURRENT_SOURCE_DIR}/../proto)
set(speech_files speech.proto)  

set(speech_h "")
set(speech_c "")
foreach(speech_file ${speech_files})
    string(REPLACE ".proto" ".pb.h" speech_h ${speech_file})
    string(REPLACE ".proto" ".pb.cc" speech_c ${speech_file})  
    if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}${speech_c})
        add_custom_command(
            # 表示在项目执行之前要执行的指令
            PRE_BUILD
            # 要执行的指令名称  
            COMMAND protoc
            # 要执行的指令的运行参数选项
            ARGS --experimental_allow_proto3_optional --cpp_out=./ -I ../../proto ../../proto/speech.proto 
            # 指定命令依赖项
            DEPENDS ${speech_path}/${speech_file}
            # 指定要生成的目标名称
            OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${speech_c}
            COMMENT "生成speech源码框架代码文件: " ${CMAKE_CURRENT_BINARY_DIR}/${speech_c}
        )
    endif()
    # 将cxx文件保存
    list(APPEND speech_srcs ${CMAKE_CURRENT_BINARY_DIR}/${speech_c})
endforeach()
    # 获取源码文件
    set(speech_ser_files "")
    aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/source speech_ser_files)
    # 添加生成目标
    add_executable(server ${speech_ser_files} ${speech_srcs})
    # 添加链接库
    target_link_libraries(server -lgflags -lspdlog -lfmt -lbrpc -lssl -lcrypto -lprotobuf -lleveldb -letcd-cpp-api -lcpprest -lcurl /usr/local/lib/libjsoncpp.so.19)

    set(speech_cli_files "")
    aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/test/ speech_cli_files)
    message("---test:  " ${speech_cli_files} )
    add_executable(client ${speech_cli_files} ${speech_srcs})
    target_link_libraries(client -lgflags -lspdlog -lfmt -lbrpc -lssl -lcrypto -lprotobuf -lleveldb -letcd-cpp-api -lcpprest -lcurl /usr/local/lib/libjsoncpp.so.19)
    
    # 设置头文件路径
    include_directories(${CMAKE_CURRENT_BINARY_DIR})
    include_directories(${CMAKE_CURRENT_BINARY_DIR}/../source)
    include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common)

    # 设置安装路径
    # INSTALL(TARGETS server client RUNTIME DESTINATION bin)